﻿using Dtos;
using IBLL;
using Microsoft.AspNetCore.Mvc;
using Model;
using System;
using System.Threading.Tasks;

namespace _2022_2_28.Controllers
{
    public class GradesController : Controller
    {
        private IGradesBll _bll;
        public GradesController(IGradesBll bll)
        {
            _bll = bll;
        }
        public async Task<IActionResult> Index()
        {
            var data = await _bll.GetAll();
            return View(data);
        }

        [HttpGet]
        public IActionResult Add() 
        {
            return View();
        }

        [HttpPost]
        public async Task<IActionResult> Add(string title) 
        {
            var a = await _bll.AddGradesAsync(title);
            return RedirectToAction("Index");
        }

        [HttpGet]
        public async Task<IActionResult> Update(Guid id) 
        {
            var data = await _bll.GetGradesByIdAsync(id);
            return View(data);
        }

        [HttpPost]
        public async Task<IActionResult> Update(GradesDto g) 
        {
            var data = await _bll.UpdateGradesAsync(g.Id,g.Title);
            return RedirectToAction("Index");
        }
        
        public async Task<IActionResult> Delete(Guid id) 
        {
            var data = await _bll.DeleteGradesAsync(id);
            return RedirectToAction("Index");
        }

    }
}
